package com.wwp.tbshop.presenter;

import android.util.Log;

import com.wwp.tbshop.activity.BrandRecommendActivity;
import com.wwp.tbshop.model.bean.BaseBean;
import com.wwp.tbshop.model.bean.BrandRecommendBean;

import java.util.List;

import retrofit2.Call;

/**
 * Created by ${wenping} on 6/17/2017.
 */

public class BrandRecommendPresenter extends BasePresenter{


    private BrandRecommendActivity mBrandRecommendActivity;

    public BrandRecommendPresenter(BrandRecommendActivity brandRecommendActivity) {
        mBrandRecommendActivity = brandRecommendActivity;
    }

    private Call<BrandRecommendBean> mRecommendBeanCall;

    public void loadBrandRecommend(){
        mRecommendBeanCall = mApiService.getRecommendBrand();
        mRecommendBeanCall.enqueue(mCallback);
    }

    private static final String TAG = "BrandRecommendPresenter";
    boolean openLog = true;
    @Override
    protected void onServerBug(int code) {
        if (openLog){
            Log.e(TAG, "onServerBug ");
        }
    }

    @Override
    protected void onConnectError(String message) {
        if (openLog){
            Log.e(TAG, "onConnectError ");
        }
    }

    @Override
    protected void onSuccess(BaseBean bean) {
        if (openLog){
            Log.e(TAG, "onSuccess ");
        }
        BrandRecommendBean brandRecommendBean = (BrandRecommendBean) bean;
        if(brandRecommendBean!=null){
            List<BrandRecommendBean.BrandBean> brandBeanList = brandRecommendBean.getBrand();
          /*  String key = brandBeanList.get(0).getKey();//key
            List<BrandRecommendBean.BrandBean.ValueBean> value = brandBeanList.get(0).getValue();
            for(int i= 0;i<value.size();i++){
                value.get(i).getPic();
                value.get(i).getName();
                BrandRecommendBean.BrandBean.ValueBean valueBean = new BrandRecommendBean.BrandBean.ValueBean();
                BrandRecommendBean.BrandBean brandBean = new BrandRecommendBean.BrandBean();
                brandBean.setKey(key);
                valueBean.setName("");
                valueBean.setPic("xx");
            }*/
            mBrandRecommendActivity.onBrandRecommendSuccess(brandBeanList);
        }else {
            if (openLog){
                Log.e(TAG, brandRecommendBean.getError_code()+"");
            }
        }
    }
}
